//
//  ViewController.m
//  FKMapKitDemo
//
//  Created by 云眼科技 on 16/7/19.
//  Copyright © 2016年 CloudEyes. All rights reserved.
//

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController ()<CLLocationManagerDelegate>{
//    CLGeocoder *_geocoder;
//    CLLocationManager *_locationManager;
}

@end

@implementation ViewController




- (void)viewDidLoad {
    [super viewDidLoad];
//    _geocoder = [[CLGeocoder alloc] init];
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    
    
    
    if (![CLLocationManager locationServicesEnabled]) {
        NSLog(@"定位服务未打开");
        return;
    }

        locationManager.delegate = self;
        //精度
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        //定位频率
        CLLocationDistance distance = 10.f;//10米定位一次
        
        locationManager.distanceFilter = distance;
    
    
    //判断设备是否是8.0以后
    if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
        //    [locationManager requestAlwaysAuthorization];
        
        //设置一次授权
        [locationManager requestWhenInUseAuthorization];
    }

        
        [locationManager startUpdatingLocation];
    
    
    
}




#pragma mark - delegate

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    CLLocation *location = [locations firstObject];
    CLLocationCoordinate2D coordinate = location.coordinate;
    NSLog(@"精度 = %f   纬度 = %f", coordinate.longitude, coordinate.latitude);
}



//#pragma mark 根据坐标取得地名
//-(void)getAddressByLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude{
//    //反地理编码
//    CLLocation *location=[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
//    [_geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
//        CLPlacemark *placemark=[placemarks firstObject];
//        NSLog(@"详细信息:%@",placemark.addressDictionary);
//    }];
//}


@end
